<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
{{include file="layouts/_head"}}
</head>
<body>
<div class="main">
    <ol class="breadcrumb">
        <li><i class="icon_home iconfont"></i>首页</li>
        <li>产品管理</li>
        <li class="active">产品列表</li>
    </ol>
    <div class="main-head text-left">
        <form class="form-inline" action="" method="get">
            <select class="form-control" name="category_id">
                <option value="">全部分类</option>
                {{volist name="$categorys" key="key" id="vo"}}
                {{if Request()->category_id == $vo.id}}
                <option selected="true" value="{{$vo.id}}">{{php}}for($i=1; $i<$vo['level']; $i++) {echo '&nbsp;&nbsp;&nbsp;&nbsp;';}{{/php}}{{$vo.name}}</option>
                {{else}}
                <option value="{{$vo.id}}">{{php}}for($i=1; $i<$vo['level']; $i++) {echo '&nbsp;&nbsp;&nbsp;&nbsp;';}{{/php}}{{$vo.name}}</option>
                {{/if}}
                {{/volist}}
            </select>
            <select class="form-control" name="brand_id">
                <option value="">全部品牌</option>
                {{volist name="$brands" key="key" id="vo"}}
                <option {{if Request()->brand_id == $vo.id}} selected {{/if}} value="{{$vo.id}}">{{$vo.name}}</option>
                {{/volist}}
            </select>
            <input type="text" class="form-control" name="keyword" value="{{$Request.param.keyword}}" placeholder="产品名" >
            <button type="submit" class="btn btn-primary">搜索</button>
        </form>
    </div>
    <div class="bg-1 clearfix main-head-info">
        <a class="btn btn-success btn-sm" href="{{:url('/admin/product/create')}}">创建产品</a>
        <button type="submit" class="btn btn-danger btn-sm" onclick="delAction()">批量删除</button>
        <span class="pull-right margin-t-5">共有数据：<strong>{{$products->total()}}</strong> 条</span>
    </div>
    <div class="main-con">
        {{if $products->total() > 0}}
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th><input type="checkbox" name="" value=""></th>
                    <th>排序</th>
                    <th>产品名</th>
                    <th>分类</th>
                    <th>品牌</th>
                    <th>状态</th>
                    <th>添加时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {{volist name="products" id="vo" key="key" }}
                <tr id="{{$vo.id}}">
                    <td><input type="checkbox" /></td>
                    <td>{{$vo.sort}}</td>
                    <td class="text-l">{{$vo.name}}</td>
                    <td>{{$vo.full_category_name}}</td>
                    <td>{{$vo.brand_name ? $vo.brand_name : '无'}}</td>
                    <td>
                        {{if $vo.status == 1}}<span class="label label-success">上架</span>{{else}}<span class="label label-danger radius">下架</span>{{/if}}
                    </td>
                    <td>{{$vo.create_time|substr=0,10}}</td>
                    <td>
                        <a class="btn btn-primary btn-xs" href="{{:url('/admin/product/edit')}}?id={{$vo.id}}">编辑</a>
                        <button type="button" class="btn btn-danger btn-xs" onClick="delAction({{$vo.id}})">删除</button>
                    </td>
                </tr>
                {{/volist}}
            </tbody>
        </table>
        <div class="page">
        {{$products->appends(Request()->get())->render()|raw}}
        </div>
        {{else}}
        <p class="color-red text-center">数据为空！</p>
        {{/if}}
    </div>
</div>
{{include file="layouts/_foot"}}
<script type="text/javascript">
function delAction(id = '') {
    if (id == '') {
        var trs = $("tbody :checkbox:checked").parents("tr");
        if (trs.length <= 0) {
            layer.msg('请勾选需删除的数据', {icon: 5, time: 1500}); return false;
        }
        var ids = '';
        for (var i = 0; i < trs.length; i++) {
            ids += trs[i].id+',';
        }
        id = ids.substr(0, ids.length - 1);
    }
    layer.confirm('确认删除？', function(index) {
        layer.closeAll(); var load = layer.load();
        $.ajax({
            type: 'GET',
            url: '{{:url("/admin/product/delete")}}?id='+id,
            dataType: 'json',
            success: function(res) {
                layer.close(load);
                if (res.code == 401) {
                    goLogin(); return false;
                }
                if (res.code == 200) {
                    layer.msg('提交成功', { time: 1500 }, function () { window.location.reload(); });
                } else if (res.code == 400) {
                    layer.msg(res.message); return false;
                } else {
                    layer.msg('操作失败'); return false;
                }
            }
        });     
    });
}
</script>
</body>
</html>